<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>收款单列表</title>
	<#include "/common/resource.ftl">
</head>
<body>

<div class="ui-operation">
    <div class="ui-search-items layui-form">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">老人姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="elderName" class="layui-input">
                </div>
            </div>
            <#--<div class="layui-inline">
                <label class="layui-form-label">验证日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="date" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">验证链接</label>
                <div class="layui-input-inline">
                    <input type="tel" name="url" class="layui-input">
                </div>
            </div>-->
        </div>
    </div>
    <div class="ui-buttons">
        <div class="layui-btn-group tools">
            <button class="layui-btn layui-btn-normal open-dialog" p="url:'${params.contextPath}/view/business/receipt/receipt_edit.htm',title:'添加收款单',width:'600px',height:'100%'"><i class="fa fa-plus"></i>添加</button>
            <button class="layui-btn layui-btn-normal modify-button" p="url:'${params.contextPath}/view/business/receipt/receipt_edit.htm',title:'编辑收款单',width:'600px',height:'100%'"><i class="fa fa-pencil"></i>修改</button>
            <button class="layui-btn layui-btn-normal remove-button" reurl="${params.contextPath}/web/receipt/delete.json"><i class="fa fa-remove"></i>删除</button>
            <button class="layui-btn layui-btn-normal accept-button" reurl="${params.contextPath}/web/receipt/accept.json"><i class="fa fa-pencil"></i>入账</button>
        </div>
        <div class="ui-searchs">
            <#--<div class="value"><input type="text" name="name" value="" placeholder="名称"/></div>-->
            <input type="button" value="搜索" class="layui-btn layui-btn-danger search-button"/>
        </div>
    </div>
</div>
<div class="ui-content" style="padding-left: 10px;padding-right:10px;">
    <table id="datagrid" options="url:'${params.contextPath}/web/receipt/list.json',params:'getSearchParams',dblClickRow:'showDetail'">
        <thead>
			<tr>
				<th data-options="field:'id',checkbox:true"></th>
				<th data-options="field:'elderName',width:100,align:'left'">老人姓名</th>
				<th data-options="field:'beginDateStr',width:120,align:'left'">开始日期</th>
				<th data-options="field:'endDateStr',width:120,align:'left'">结束日期</th>
                <th data-options="field:'statusStr',width:100,align:'left',formatter:formatState">入账状态</th>
				<th data-options="field:'bedAmount',width:100,align:'left'">床位费</th>
				<th data-options="field:'nurseAmount',width:100,align:'left'">护理费</th>
				<th data-options="field:'liveAmount',width:100,align:'left'">生活费</th>
				<th data-options="field:'otherAmount',width:100,align:'left'">其他费用</th>
				<th data-options="field:'totalAmount',width:100,align:'left'">总费用</th>
				<th data-options="field:'payTypeStr',width:100,align:'left'">支付方式</th>
				<th data-options="field:'remark',width:100,align:'left'">备注</th>
				<th data-options="field:'createTimeStr',width:200,align:'left'">创建时间</th>
			</tr>
        </thead>
    </table>
</div>
<script type="text/javascript">
    function getSearchParams() {
        return {elderName: $("input[name='elderName']").val()};
    }
    var showDetail = function (index, row) {
        var url = "${params.contextPath}/view/business/receipt/receipt_detail.htm?id=" + row.id;
        DialogManager.openDialog("url:'" + url + "',title:'收款单详情',width:'600px',height:'600px'");
    };
    //formatter:formatState
    function formatState(row) {
        if (row.status == 2) {
            return '<span class="ui-accept">' + row.statusStr + '</span>';
        } else if (row.status == 1) {
            return '<span class="ui-stop">' + row.statusStr + '</span>';
        }
        return row.statusStr;
    }

    $(function () {
        $(".remove-button").click(function () {
            var rows = DataGrid.getCheckedRows();
            if (!rows || rows.length == 0) {
                layer.msg("请选择删除记录")
                return false;
            }
            var ids = new Array();
            for (var i = 0, length = rows.length; i < length; i ++) {
                var row = rows[i];
                if (row.status == 2) {
                    $.message("已入账记录无法删除，请去除勾选");
                    return;
                }
                ids.push(row.id);
            }

            var url = $(this).attr("reurl");
            layer.confirm('确定删除记录', function () {
                $.ajaxRequest({
                    type: 'post',
                    url: url,
                    data: {ids: ids.join(",")},
                    success: function (data) {
                        $.message(data.message);
                        if (data.success) {
                            DataGrid.reload();
                        }
                    }
                });
            });
        });

        $(".accept-button").click(function () {
            var row = DataGrid.getSelectRow();
            if (!row) {
                layer.msg("请选择需要入账的记录")
                return false;
            }
            if (row.status == 2) {
                $.message("已入账记录无需重新入账");
                return;
            }

            var url = $(this).attr("reurl");
            $.ajaxRequest({
                type: 'post',
                url: url,
                data: {id: row.id},
                success: function (data) {
                    $.message(data.message);
                    if (data.success) {
                        DataGrid.reload();
                    }
                }
            });
        });

        $(".modify-button").click(function () {
            var row = DataGrid.getSelectRow();
            if (!row) {
                $.message("请选择需要修改的记录")
                return false;
            }
            if (row.status == 2) {
                $.message("已入账记录无法修改");
                return;
            }
            var p = $(this).attr("p");
            DialogManager.singleSelected(p);
        });
    });
</script>
</body>

</html>
